package com.example.model.title.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.example.annotations.Autowired;
import com.example.annotations.Service;
import com.example.db.SqlBuilder;
import com.example.db.TableService;
import com.example.db.model.IPage;
import com.example.model.title.model.ChannelModel;
import com.example.model.title.model.ContentModel;
import com.example.model.title.service.ContentModelService;

/**
 * @Classname ContentServiceImpl
 * @Description TODO
 * @Date 2022/8/7 1:05
 * @Created by XiongXiong
 * @Author: X.I.O
 */
@Service
public class ContentServiceImpl implements ContentModelService {

    @Autowired
    TableService tableService;

    @Override
    public IPage<ContentModel> page(Integer pageNumber, Integer pageSize, JSONObject obj) {
        SqlBuilder sqlBuilder=tableService.getSqlBuilder(ChannelModel.class);
        if(obj != null){

        }
        sqlBuilder.page(pageNumber,pageSize);
        sqlBuilder.orderByDesc("createdate");
        IPage<ContentModel> iPage=tableService.getPage(sqlBuilder,ContentModel.class);
        return iPage;
    }

    @Override
    public ContentModel save(ContentModel contentModel) {
        tableService.save(contentModel,ContentModel.class);
        return contentModel;
    }

    @Override
    public ContentModel update(ContentModel contentModel) {
        tableService.updateById(contentModel,ContentModel.class);
        return contentModel;
    }

    @Override
    public ContentModel getId(Object id) {
        ContentModel contentModel=tableService.getOneById(id,ContentModel.class);
        return contentModel;
    }
}
